package com.example.mapper;

import com.example.entity.Menu;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 菜单表 Mapper 接口
 * </p>
 *
 * @author ccf@lijiaqiang
 * @since 2023-10-29
 */
@Mapper
public interface SysMenuMapper extends BaseMapper<Menu> {
    /**
     * 自定义方法, 根据用户id查新用户权限
     */
    @Select("select " +
            "    distinct m.perms " +
            "from " +
            "    sys_user_role ur left join sys_role r on ur.role_id = r.id " +
            "     left join sys_role_menu rm on ur.role_id = rm.role_id " +
            "     left join sys_menu m on m.id = rm.menu_id " +
            "where  " +
            "      user_id = #{userId} " +
            "and r.status = 0 and m.status = 0;")
    List<String> selectPermsByUserId(Long userId);
}
